package com.wfm.time;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        // 获取当前日期时间
        LocalDateTime now = LocalDateTime.now();
        System.out.println("当前时间："+now);
        // 当前时间到前三天日期时间
        now = now.minusDays(3);
        System.out.println("前三天："+now);
        // 获取时间戳

        // 把时间转化为时间戳
        Instant instant = now.toInstant(java.time.ZoneOffset.of("+8"));
        long l = instant.toEpochMilli();
        System.out.println("时间戳："+l);

        // 格式化字符串为时间
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime parse = LocalDateTime.parse("2025-01-01 12:30:45", dateTimeFormatter);
        System.out.println("格式化字符串为时间："+parse);

        // 把时间转化为字符串
        String format = now.format(dateTimeFormatter);
        System.out.println("时间转化为字符串："+format);

        // 计算时间的间隔
        LocalDateTime now2 = LocalDateTime.now();
        long between = ChronoUnit.SECONDS.between(now, now2);
        System.out.println("时间间隔秒："+between);
        between = ChronoUnit.MINUTES.between(now, now2);
        System.out.println("时间间隔分钟："+between);
        between = ChronoUnit.HOURS.between(now, now2);
        System.out.println("时间间隔小时："+between);
        between = ChronoUnit.DAYS.between(now, now2);
        System.out.println("时间间隔天："+between);

    }
}
